package com.esm.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.esm.daoimpl.DepartmentCrodeImpl_lxy;
import com.esm.model.Department_lxy;
import com.esm.model.DepartmentCrode_lxy;
import com.esm.model.User;
import com.esm.service.DepartmentCrodeService_lxy;
import com.esm.serviceimpl.DepartmentCrodeServiceImpl_lxy;

import net.sf.json.JSONObject;
/**
 * 这是一个部门记录的Controller
 * @author LiuXingYu
 *
 */
public class DepartmentCrodeController_lxy extends HttpServlet{
	DepartmentCrodeService_lxy dc=new DepartmentCrodeServiceImpl_lxy();
			   @Override
			protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
				// TODO Auto-generated method stub
				   doPost(req, resp);
			}
             @Override
            protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            // TODO Auto-generated method stub
            	 resp.setCharacterEncoding("utf8");
    	    	 PrintWriter pw=resp.getWriter();
    	    	 HttpSession session=req.getSession();
    	    	 int page =Integer.parseInt(req.getParameter("page"));
    	    	 int rows =Integer.parseInt(req.getParameter("rows"));
    	    	 String currentUser=((User)session.getAttribute("currentUser")).getUname();
    	    	 int total=dc.findDepartmentCrodeCount();
    	    	 List<DepartmentCrode_lxy> departmentCrodes=dc.findDepartmentCrodes(page, rows);
    	    	 JSONObject j=new JSONObject();
    	    	 j.put("total", total);
    	    	 j.put("rows", departmentCrodes);
    	    	 pw.write(j.toString());
    	    	 pw.flush();
    	    	 pw.close();
            }
}
